<?php
// $Id: RadioInput.php 27 2010-11-16 12:49:54Z mjohnson60@gmail.com $


/**
 * Enter description here ...
 * 
 * @author Mark Phillip Johnson
 * @version 1.0
 * @copyright Copyright (c) 2010, markjohnson
 * @license http://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
 *
 */
class RadioInput extends FormElement
{
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $selected = FALSE;
	
	var $return_value = '';

	/**
	 * __construct()
	 * 
	 * Enter description here ...
	 * 
	 */
	function __construct($name, $value, $id = NULL, $parent = NULL, $attributes = array(), $title = '', $selected = FALSE)
	{
		$this->type = 'radio';
		$this->selected = $selected;
		$this->title = $title;
		
		if (is_array($value))
		{
			parent::__construct($value, $name);
		}
		else
		{
			parent::__construct(NULL, $name, $value, $id, $parent, $attributes);
		}
	}

	/* 
	 * @see FormElement::_compile()
	 */
	public function _compile()
	{
		return $this->render();
	}

	/* 
	 * @see FormElement::render()
	 */
	public function render()
	{
		$this->addHtmlClasses(array(
			'form-radio'
		));
		
		$output = '<input type="radio" id="' . $this->id . '" name="' . $this->name . '" value="' . $this->value . '"' . ($this->selected === TRUE ? ' checked="checked"' : '') . attributes($this->attributes) . ' />';
		if (!is_null($this->title))
		{
			$output = '<label class="option" for="' . $this->id . '">' . $output . ' ' . $this->title . '</label>';
		}
		
		$old_title = $this->title;
		unset($this->title);
		
		$output = parent::render($output);
		
		$this->title = $old_title;
		
		return $output;
	}
}